#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

bool canSortArray(vector<int>& nums) {
    vector<int> count;
    int n = nums.size();
    for (int i = 0; i < n; i++)
        count.push_back(get(nums[i]));

    int l = 0, r = 0;
    while (r < n)
    {
        if (r != 0 && count[r] != count[r - 1])
        {
            sort(nums.begin() + l, nums.begin() + r);
            l = r;
        }
        r++;
    }
    if (l != r)  sort(nums.begin() + l, nums.begin() + r);

    for (int i = 0; i < n; i++)    cout << nums[i] << " ";
    for (int i = 1; i < n; i++)
        if (nums[i] < nums[i - 1])
            return false;

    return true;
}

int get(int x)
{
    int res = 0;
    while (x)
    {
        if (x & 1)   res++;
        x >>= 1;
    }
    return res;
}